import WorkerMSDB
import sys
reader = WorkerMSDB.Worker('localhost', '1433', 'base', 'mssa', 'msms')
reader.connect()
c = reader.connection.cursor()
query = 'SELECT TOP (30) id,deviceId,eventId,eventTime,rs232str,SaveTime FROM _rs232_data WHERE deviceId=5 ORDER BY eventTime DESC'
c.execute(query)
d = c.fetchall()

#for s in d: print s

for e in d:
    s = str(e[4])
    print s.decode('cp866')
    #for i in e[4]: sys.stdout.write('%s:%d ' % (i.decode('cp866'), ord(i)))
    sys.stdout.write('\n')

	
